Image processing method and terminal

ABSTRACT

An image processing method includes displaying, by a terminal, a preview image, obtaining, by the terminal, at least one first image in the preview image, receiving, by the terminal, a photographing instruction, obtaining, by the terminal, at least one second image, detecting, by the terminal, a moving target based on the first image and the second image, and splitting, by the terminal, the moving target from the first image and the second image. The method further includes performing fusion processing on the first image and the second image after the splitting.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a national stage of International Application No.PCT/CN2017/104753, filed Sep. 30, 2017, which claims priority to ChinesePatent Application No. 201710582412.4, filed on Jul. 17, 2017. All ofthe aforementioned applications are hereby incorporated by reference intheir entireties.

TECHNICAL FIELD

This application relates to the field of image processing, and inparticular, to an image processing method and a terminal.

BACKGROUND

Currently, in addition to a terminal such as a camera specially used forphotographing, many terminals are integrated with a camera function, forexample, a smartphone and a tablet. When a user uses a terminal toperform photographing, a photographed image may include an object thatis not expected to appear in the image. For example, duringphotographing of an image of a landscape, a building, or the like, amoving target such as a walking person or a flying object is alsoincluded in the image when the image is photographed. In addition, asimilar case may also occur during photographing of a portrait of aperson, and a moving target such as a walking passer-by, an animal, oran automobile is also included in an image when the image isphotographed. These moving targets are objects that are not expected toappear in the image.

In a typical scenario, in a busy season of tourism, a popular touristattraction is filled with endless streams of tourists, and a user isconfronted with a suddenly passing passer-by at any time when using amobile phone to perform photographing. Consequently, the passer-by isalso in a photographed image.

In an existing image processing method, to remove a moving target froman image, a plurality of images need to be obtained duringphotographing, so that the moving target in the plurality of images hasan apparent moving distance. After the user taps a photographing key,the user needs to hold the mobile phone stable and wait for a relativelylong time, for example, four seconds, to obtain a plurality of imagesthat satisfy image processing. Consequently, this causes low imagephotographing efficiency and poor user experience.

SUMMARY

Embodiments of the present invention provide an image processing methodand a terminal. After a user taps a photographing key, a waiting time isapparently shortened, photographing efficiency is high, and userexperience is good.

According to a first aspect, an image processing method is provided, andincludes: displaying, by a terminal, a preview image; obtaining, by theterminal, at least one first image in the preview image; receiving, bythe terminal, a photographing instruction; obtaining, by the terminal,at least one second image; detecting, by the terminal, a moving targetbased on the first image and the second image; and splitting, by theterminal, the moving target from the first image and the second image,and performing fusion processing on the first image and the second imageafter the splitting.

In this embodiment of the present invention, to remove a moving targetfrom an image, a plurality of images need to be obtained. It is not thatthe terminal obtains the plurality of images only after receiving thephotographing instruction, but the terminal starts to obtain the imagesin an image preview phase before receiving the photographinginstruction. Therefore, a quantity of images that need to be obtainedafter the photographing instruction is received is reduced, so that arequired photographing time is apparently shortened, photographingefficiency is high, and user experience is good.

In a possible implementation, the displaying, by the terminal, a previewimage includes: displaying, by the terminal, the preview image when acamera function of the terminal is enabled; or displaying, by theterminal, the preview image when a camera function of the terminalenters a first photo mode; or displaying, by the terminal, the previewimage when the terminal receives the photographing instruction and afirst time interval elapses. According to the implementation, the imageprocessing method may be applied to any photo mode after the camerafunction is enabled, or applied only to a preset photo mode after thecamera function is enabled. The preset photo mode may be an existingportrait photo mode, or a newly added passer-by removal mode. The imageprocessing method not only may be applied to first-time photographingafter the camera function is enabled, but also may be applied tosubsequent photographing after the first-time photographing iscompleted.

In a possible implementation, the obtaining, by the terminal, at leastone first image in the preview image includes: obtaining, by theterminal, a preset quantity of first images in the preview image.According to the implementation, the terminal may obtain the presetquantity of images from the preview image, to reduce a quantity ofimages obtained in a photographing phase, and correspondingly reduce arequired photographing time.

In a possible implementation, the obtaining, by the terminal, a presetquantity of first images in the preview image includes: obtaining, bythe terminal, one of the first images in the preview image each time asecond time interval elapses, until the preset quantity of first imagesin the preview image are obtained. According to the implementation, theterminal no longer obtains an image after obtaining the preset quantityof images in a preview phase, so that a processing resource and astorage resource of the terminal can be saved.

In a possible implementation, the obtaining, by the terminal, a presetquantity of first images in the preview image includes: obtaining, bythe terminal, one of the first images in the preview image each time asecond time interval elapses, and when a quantity of obtained firstimages in the preview image exceeds the preset quantity, retaining thepreset quantity of recently obtained first images in the preview image.According to the implementation, after obtaining the preset quantity ofimages in the preview phase, the terminal continues to obtain an image,and retains the preset quantity of recently obtained first images in thepreview image, so that not only a storage resource of the terminal canbe saved, but also a relatively good image processing effect can beensured.

In a possible implementation, the obtaining, by the terminal, at leastone first image in the preview image includes: obtaining, by theterminal, at least two first images in the preview image within a thirdtime interval. According to the implementation, the terminal determines,based on a time span of the plurality of images obtained in the previewphase, whether to continue to obtain an image, so that not only astorage resource of the terminal can be saved, but also a relativelygood image processing effect can be ensured.

In a possible implementation, before the obtaining, by the terminal, atleast one first image in the preview image, the method further includes:obtaining, by the terminal, motion data of the terminal; anddetermining, by the terminal based on the motion data, that the terminalis in a stable state. According to the implementation, the terminalfirst determines that the terminal is in the stable state, and thenobtains the at least one first image in the preview image, to ensurethat quality of the obtained images meets a requirement.

In a possible implementation, the detecting, by the terminal, a movingtarget based on the first image and the second image includes:determining, by the terminal, depth of field information of the firstimage and depth of field information of the second image based on thefirst image and the second image; and detecting, by the terminal, themoving target based on the depth of field information. According to theimplementation, the moving target is detected by using the depth offield information, so that accuracy of detecting the moving target canbe effectively improved.

In a possible implementation, the terminal has dual camera lenses.According to the implementation, the depth of field information can berelatively accurately determined by using the dual camera lenses, sothat the moving target can be accurately detected based on the depth offield information.

According to a second aspect, an embodiment of the present inventionprovides a terminal. The terminal may implement functions performed inthe method design in the foregoing first aspect, and the functions maybe implemented by hardware or may be implemented by hardware executingcorresponding software. The hardware or the software includes one ormore modules corresponding to the foregoing functions.

According to a third aspect, an embodiment of the present inventionprovides a terminal. A structure of the terminal includes a processor,and the processor is configured to support the terminal in performing acorresponding function in the foregoing method in the first aspect. Theterminal may further include a camera lens, and the camera lens isconfigured to obtain an image. The terminal may further include adisplay screen, and the display screen is configured to display animage. The terminal may further include a memory. The memory isconfigured to couple to the processor, and stores a program instructionand data that are necessary for the terminal.

According to a fourth aspect, an embodiment of the present inventionprovides a chip. The chip may be disposed in a terminal, and the chipincludes a processor and an interface. The processor is configured tosupport the chip in performing a corresponding function in the methodaccording to the first aspect. The interface is configured to supportthe chip in communicating with another chip or another network element.The chip may further include a memory. The memory is configured tocouple to the processor, and stores a program instruction and data thatare necessary for the chip.

According to a fifth aspect, an embodiment of the present inventionprovides a computer storage medium, configured to store a computersoftware instruction used by the foregoing terminal. The computersoftware instruction includes a program designed for executing the firstaspect.

According to a sixth aspect, an embodiment of the present inventionprovides a computer program product, including an instruction. When theprogram is executed by a computer, the instruction enables the computerto perform a function performed by the terminal in the method designaccording to the first aspect.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a schematic diagram of an application scenario of an imageprocessing method according to an embodiment of the present invention;

FIG. 2 is a schematic structural diagram of a terminal according to anembodiment of the present invention;

FIG. 3 is a flowchart of an image processing method according to anembodiment of the present invention;

FIG. 4 is a schematic diagram of an occasion for displaying a previewimage according to an embodiment of the present invention;

FIG. 5 is a schematic diagram of sending voice prompt information by aterminal according to an embodiment of the present invention;

FIG. 6 is a schematic diagram of sending visual prompt information by aterminal according to an embodiment of the present invention;

FIG. 7 is another schematic diagram of sending visual prompt informationby a terminal according to an embodiment of the present invention;

FIG. 8 is a schematic diagram of obtaining an image by a terminalaccording to an embodiment of the present invention;

FIG. 9 is another schematic diagram of obtaining an image by a terminalaccording to an embodiment of the present invention;

FIG. 10 is a schematic flowchart of a moving target detection methodaccording to an embodiment of the present invention;

FIG. 11 is a schematic diagram of a depth of field determining methodaccording to an embodiment of the present invention;

FIG. 12 is another schematic diagram of a depth of field determiningmethod according to an embodiment of the present invention;

FIG. 13 is a schematic diagram of obtaining a depth of field map by aterminal according to an embodiment of the present invention;

FIG. 14 is a schematic diagram of a method for performing fusionprocessing on a plurality of images according to an embodiment of thepresent invention;

FIG. 15 is a schematic structural diagram of a terminal according to anembodiment of the present invention; and

FIG. 16 is another schematic structural diagram of a terminal accordingto an embodiment of the present invention.

DESCRIPTION OF EMBODIMENTS

FIG. 1 is a schematic diagram of an application scenario of an imageprocessing method according to an embodiment of the present invention.As shown in FIG. 1, when a user 101 uses a terminal to photograph aphotographed person 102, a moving target 103 walks behind thephotographed person 102. After the photographing is completed and animage is obtained, the image that is not processed includes not only thephotographed person 102 but also the moving target 103. After the movingtarget 103 is removed from the image by using the image processingmethod provided in the embodiments of the present invention, an obtainedimage includes only the photographed person 102 and does not include themoving target 103.

It should be noted that, FIG. 1 is only an example of the applicationscenario in this embodiment of the present invention, and is not used asa limitation to the application scenario in this embodiment of thepresent invention. The application scenario in this embodiment of thepresent invention may alternatively be that the moving target 103 passesby before the photographed person 102 or the moving target 103 passes bybeside the photographed person 102. The moving target 103 may be apedestrian shown in FIG. 1, or may be a moving animal or another object.For example, a possible scenario is that a vehicle passes by behind thephotographed person, or a possible scenario is that the moving targetpasses by behind the user when the user uses the terminal to take aself-portrait. In other words, this embodiment of the present inventionmay be applied to a scenario in which the moving target passes by ineach direction of the photographed person when the user photographs thephotographed person or the user takes a self-portrait.

According to the image processing method provided in the embodiments ofthe present invention, image processing is performed on an imageobtained by the terminal in a preview phase and an image obtained by theterminal in a photographing phase, to detect a moving target, and removethe moving target from the image. In this embodiment of the presentinvention, a first image is used to represent the image that is obtainedby the terminal in the preview phase, and a second image is used torepresent the image that is obtained by the terminal in thephotographing phase. Usually, the terminal enters the preview phaseafter a camera function is enabled. In this case, the terminal maycontinuously acquire images by using a camera lens. For example, theterminal acquires 24 frames of images (also referred to as 24 images)per second, and displays the acquired images by using a display screen.In this case, the user may view a plurality of dynamic images by usingthe display screen. It may be understood that, because first imagesobtained by the terminal in the preview phase are used to adjust acamera lens parameter, assist in framing, and the like, the terminalusually does not store these first images. Usually, the terminal entersthe photographing phase when receiving a photographing instruction. Inthis case, the terminal may obtain one or more images by using thecamera lens, and store these second images. A manner in which theterminal receives the photographing instruction may include: The usertaps a photographing function icon displayed on the screen, the userpresses a function key of a mobile phone, the user sends a voice forphotographing, or the user makes a preset gesture. It may be understoodthat when the terminal completes the photographing, the terminal mayenter the preview phase again.

The image processing method provided in the embodiments of the presentinvention may be applied to any terminal that has a camera function. Theterminal may acquire an image by using the camera lens, to have thecamera function. The terminal may be a mobile phone, a cellulartelephone, a tablet (tablet personal computer, TPC), a laptop computer(laptop computer), a digital camera, a digital camcorder, a projectiondevice, a wearable device (wearable device), a personal digitalassistant (personal digital assistant, PDA), an e-book reader (e-bookreader), a virtual reality intelligent device, a digital broadcastingterminal, a message transceiver device, a game console, a medicaldevice, a fitness device, a scanner, or the like. The terminal mayestablish communication with a network by using a wireless wide areanetwork (wireless wide area network, WWAN) or a wireless local accessnetwork (wireless local access network, WLAN).

In the embodiments of the present invention, descriptions are providedby using an example in which the terminal is a mobile phone. FIG. 2 is astructural block diagram of a mobile phone 100 related to theembodiments of the present invention. Referring to FIG. 2, the mobilephone 100 includes components such as a radio frequency (radiofrequency, RF) circuit 110, a memory 120, an input unit 130, a displayunit 140, a processor 150, a power supply 160, a sensor 170, and acamera lens 180. A person skilled in the art may understand that astructure of the terminal shown in FIG. 2 does not constitute alimitation to the terminal, and the terminal may include more componentsor fewer components than those shown in the figure, or some componentsmay be combined, or a different component deployment may be used.

The RF circuit 110 may be configured to: receive and send information,or receive and send a signal during a call, for example, exchangeinformation with a device such as a server, and send the receivedinformation to the processor 150 for processing. The RF circuit 110usually includes but is not limited to an antenna, at least oneamplifier, a transceiver, a coupler, a low noise amplifier (low noiseamplifier, LNA), a duplexer, and the like. In addition, the RF circuit110 may alternatively communicate with a network and another devicethrough wireless communication. Any communications standard or protocolmay be used for the wireless communication, and includes but is notlimited to global system for mobile communications (Global System forMobile communications, GSM), general packet radio service (GeneralPacket Radio Service, GPRS), a code division multiple access (CodeDivision Multiple Access, CDMA) system, a wideband code divisionmultiple access (Wideband Code Division Multiple Access, WCDMA) system,a long term evolution (Long Term Evolution, LTE) system, email, shortmessaging service (Short Messaging Service, SMS), and the like.

The memory 120 may be configured to store a software program and amodule. The processor 150 runs the software program and the module thatare stored in the memory 120, so that the mobile phone performs theforegoing image processing method. The memory 120 may mainly include aprogram storage area and a data storage area. The program storage areamay store an operating system, an application program (such as a soundplaying function or an image playing function) required for implementingthe foregoing image processing method, and the like. The data storagearea may store data (such as audio data and an address book) createdbased on usage of the mobile phone 100, and the like. In addition, thememory 120 may include a volatile memory (volatile memory), for example,a nonvolatile dynamic random access memory (Nonvolatile Random AccessMemory, NVRAM), a phase-change random access memory (Phase Change RAM,PRAM), a magnetoresistive random access memory (Magnetoresistive RAM,MRAM), and the like. The memory 120 may further include a nonvolatilememory, for example, at least one magnetic disk storage device, anelectrically erasable programmable read-only memory (ElectricallyErasable Programmable Read-Only Memory, EEPROM), a flash memory devicesuch as a NOR flash memory (NOR flash memory) or a NAND flash memory(NAND flash memory), or a semiconductor device such as a solid-statedrive (Solid State Disk, SSD). The memory 120 may further include acombination of the foregoing types of memories.

The input unit 130 may be configured to receive an instruction enteredby a user. Specifically, the input unit 130 may include a touch panel131 and another input device 132. The touch panel 131, also referred toas a touchscreen, may collect a touch operation (for example, anoperation performed by a user on the touch panel 131 or near the touchpanel 131 by using any proper object or accessory such as a finger or astylus) of the user on or near the touch panel 131, and drive acorresponding connection apparatus based on a preset program.Optionally, the touch panel 131 may include two parts: a touch detectionapparatus and a touch controller. The touch detection apparatus detectsa touch position of the user, detects a signal brought by a touchoperation, and transfers the signal to the touch controller. The touchcontroller receives touch information from the touch detectionapparatus, converts the touch information into coordinates of a touchpoint, and then sends the coordinates of the touch point to theprocessor 150. In addition, the touch controller can receive and executea command sent by the processor 150. In addition, the input unit 130 mayimplement the touch panel 131 in a plurality of types, such as aresistive type, a capacitive type, an infrared type, and a surfaceacoustic wave type. In addition to the touch panel 131, the input unit130 may include the another input device 132. Specifically, the anotherinput device 132 may include but is not limited to one or more of aphysical keyboard, a function key (such as a volume control key or apower on/off key), a trackball, a mouse, a joystick, and the like.

The display screen 140 may be configured to display information enteredby the user, information provided for the user, or the like, forexample, display an image. The display screen 140 may include a displaypanel 141. Optionally, the display panel 141 may be configured in a formof a liquid crystal display (liquid crystal display, LCD), an organiclight-emitting diode (organic light-emitting diode, OLED), or the like.Further, the touch panel 131 may cover the display panel 141. Afterdetecting a touch operation on or near the touch panel 131, the touchpanel 131 transmits the touch operation to the processor 150 todetermine a type of a touch event, and then the processor 150 provides acorresponding visual output on the display panel 141 based on the typeof the touch event. For example, after detecting an instruction forenabling a camera function, the touch panel 131 transmits theinstruction to the processor 150 to determine to enable the camerafunction, and then the processor 150 provides a corresponding previewimage on the display panel 141 based on an image obtained by the cameralens 180. In FIG. 2, the touch panel 131 and the display panel 141 areused as two independent components to implement input and outputfunctions of the terminal. However, in some embodiments, the touch panel131 may be integrated with the display panel 141 to implement the inputand output functions of the terminal.

The processor 150 is a control center of the terminal, and is connectedto various parts of the entire terminal by using various interfaces andlines. By running or executing the software program and/or module storedin the memory 120, and invoking the data stored in the memory 120, theprocessor 150 performs various functions of the mobile phone 100 andprocesses data, for example, performs the image processing method. Theprocessor 150 may be a central processing unit (central processing unit,CPU), a general-purpose processor, a digital signal processor (digitalsignal processor, DSP), an application-specific integrated circuit(application specific integrated circuit, ASIC), a field programmablegate array (field programmable gate array, FPGA) or another programmablelogical device, a transistor logical device, a hardware component, orany combination thereof. The processor 150 may implement or executevarious examples of logical blocks, modules, and circuits that aredescribed with reference to content disclosed in this application.Alternatively, the processor 150 may be a combination for implementing acomputing function, for example, a combination of one or moremicroprocessors or a combination of a DSP and a microprocessor.Optionally, the processor 150 may include one or more processing units.Optionally, an application processor and a modem processor may beintegrated in the processor 150. The application processor mainlyprocesses an operating system, a user interface, an application program,and the like. The modem processor mainly processes wirelesscommunication. It may be understood that the foregoing modem processormay alternatively not be integrated into the processor 150.

The terminal further includes the power supply 160 (for example, abattery) for supplying power to the components. Preferably, the powersupply may be logically connected to the processor 150 by using a powersupply management system, thereby implementing functions such ascharging, discharging, and power consumption management by using thepower supply management system.

The terminal further includes the sensor 170. The terminal may includeone or more sensors. Only one sensor is shown in the figure as anexample, and the terminal may include a plurality of types of sensorsthat may be but are not limited to a motion sensor, a pressure sensor, adistance sensor, an acceleration sensor, a gyro sensor, a GPS sensor, adirection sensor, a temperature sensor, and the like. In runningprocesses, different types of applications may use different sensors. Inthe embodiments of the present invention, whether the terminal is heldstable may be determined based on information about a sensor.

The terminal further includes the camera lens 180. The camera lens 180may be configured to obtain an image. The photographed object image is abitmap including a pixel dot-matrix. The camera lens 180 may include oneor more camera lenses, for example, a camera lens array including two ormore camera lenses. The camera lens 180 may include one or moreparameters. These parameters include a lens focal length, a shutterspeed, an ISO sensitivity, a resolution, and the like. When there are atleast two camera lenses, parameters of these camera lenses may be thesame or may be different. The foregoing parameters are manually set bythe user or automatically set by the mobile phone 100, to obtain animage.

Although not shown, a Bluetooth module, an audio circuit, a USB module,and the like may be further included in the terminal. Details are notdescribed herein.

FIG. 3 is a flowchart of an image processing method according to anembodiment of the present invention. The method may be based on theapplication scenario shown in FIG. 1, and may be performed by theterminal shown in FIG. 2.

The method includes the following steps.

Step 301: The terminal displays a preview image.

The terminal may display the preview image in an entire area referred toas a “full screen”) of a display screen, or may display the previewimage in a partial area of a display screen. For example, the terminaldisplays the preview image in a window. The window may be located at anylocation on the display screen, including a location such as an upperpart, a lower part, a left part, or a right part. This is not limited inthis application.

In an example, when a camera function of the terminal is enabled, theterminal displays a preview image.

The terminal may enable the camera function when receiving aninstruction sent by a user for enabling the camera function. The usermay send, in a plurality of manners, the instruction for enabling thecamera function to the terminal. These manners include: The user mayenable the terminal to enable the camera function, by using a gesture,for example, controlling the terminal to be horizontally placed for twoseconds, or drawing a shape (for example, “C”) on a touchscreen.Alternatively, the user taps an icon displayed on a screen, to enablethe terminal to enable the camera function. The icon may be anapplication icon, and an application corresponding to the applicationicon may be a camera application pre-installed in the terminal, or maybe a third-party application. Alternatively, the user may press afunction key of the mobile phone to enable the terminal to enable thecamera function. The function key may be a volume key (for example, avolume up “+” key or a volume down “−” key) or a home (home) key.Alternatively, the user may use a voice to enable the terminal to enablethe camera function. For example, the user sends a voice indication of“enabling the camera function”.

In another example, when the camera function of the terminal enters afirst photo mode, the terminal displays a preview image. In the photomode, parameters (for example, a focal length, an aperture value, ashutter value, and a light sensitivity) of the camera lens may be set,and a parameter (for example, a parameter about whether to performmoving target detection) for performing image processing on an imageobtained by the camera lens.

The camera function of the terminal may include a plurality of types ofphoto modes, for example, a landscape mode, a portrait mode, a nightshot mode, a sports mode, a macro mode, a panorama mode, and a passer-byremoval mode. The first photo mode may be any one of the foregoing photomodes, to be specific, the image processing method provided in thisembodiment of the present invention may be used when the camera functionof the terminal enters the first photo mode.

In another example, when the terminal receives a photographinginstruction and a first time interval elapses, the terminal displays apreview image. FIG. 4 is a schematic diagram of an occasion fordisplaying a preview image according to an embodiment of the presentinvention. The first time interval may be a time interval required bythe terminal to receive the photographing instruction and complete thisphotographing operation. For example, after receiving a photographinginstruction, the terminal takes a total of three seconds to obtain threeimages, and enters the preview phase again after the three seconds, andthe terminal displays a preview image. In this case, the terminal mayreceive a photographing instruction again, to perform nextphotographing. In other words, the image processing method in thisembodiment of the present invention not only may be applied to imageprocessing for first-time photographing after the camera function isenabled, but also may be applied to image processing for subsequentphotographing.

Optionally, in the foregoing examples, when displaying the previewimage, the terminal may detect a photographing subject and a movingtarget, and display the detected photographing subject and the movingtarget in a highlighted manner. For example, one color box (for example,a green box) is used for a contour of the photographing subject, andanother color box (for example, a red box) is used for the movingtarget. It should be noted that the terminal may use an existingdetection algorithm to detect the photographing subject and the movingtarget. Details are not described in this application.

Step 302: The terminal obtains at least one first image.

In an example, when determining that the terminal is in a stable state,the terminal obtains the at least one first image in the preview image.The determining, by the terminal, that the terminal is in a stable statespecifically includes: obtaining, by the terminal, motion data of theterminal; and determining, by the terminal based on the motion data ofthe terminal, that the terminal is in the stable state. A motion sensormay be integrated in the terminal. The motion data of the terminal iscollected by using the motion sensor, thereby determining whether theterminal is in the stable state, to ensure that a preview picture of acamera is stable, and a stable image can be obtained. For example, anacceleration of the terminal is collected by using the motion sensor.When the acceleration of the terminal is less than or equal to a presetacceleration threshold, it is determined that the terminal is in thestable state. When the acceleration of the terminal is greater than apreset acceleration threshold, it is determined that the terminal is inan unstable state. The preset acceleration threshold may be determinedbased on an actual situation. This is not limited in this application.

Optionally, the terminal may obtain the at least one first image afterremaining in the stable state for predetermined duration. After theterminal remains in the stable state for the predetermined duration, itindicates that the user has completed framing, so that the first imagemay be obtained. The predetermined duration may be determined based onan actual situation. This is not limited in this application.

Optionally, when starting to obtain the first image, the terminal mayrecord a first moment t1 at which the terminal starts to obtain thefirst image.

Optionally, the terminal may shake in a process of obtaining the firstimage, that is, the terminal is in the unstable state. When the terminalis in the unstable state, the terminal may stop obtaining the firstimage. When determining that the terminal is in the stable state again,the terminal starts to obtain the first image again, and re-records thefirst moment t1 at which the terminal starts to obtain the first image.The terminal may obtain a preset quantity of first images in the previewphase. The preset quantity may be preset based on an actual situation.For example, the preset quantity needs to meet a requirement ofsubsequent image processing on a quantity of first images. The presetquantity may be one or more. In other words, the terminal may obtain onefirst image, or may obtain a plurality of first images.

In an example, when the terminal determines that the terminal is in thestable state, the terminal may obtain one first image in the previewphase. Optionally, after the terminal obtains one first image, theterminal may prompt the user that the obtaining of the first image iscompleted. A prompt manner is not limited in this embodiment of thepresent invention.

In another example, when the terminal determines that the terminal is inthe stable state, the terminal may obtain a plurality of first images inthe preview phase, for example, continuously obtain two or three firstimages. Optionally, after the terminal obtains the plurality of firstimages, the terminal may prompt the user that the obtaining of the firstimages is completed. A prompt manner is not limited in this embodimentof the present invention.

The following further describes a case in which the terminal obtains theplurality of first images in the preview phase.

In an example, the terminal may first obtain one first image, and thenobtain one first image each time a preset time interval (also referredto as a second time interval or second duration) elapses, until thepreset quantity of first images are obtained. The preset time intervalis a time interval between obtaining one first image by the terminal andobtaining another first image by the terminal. The preset time intervalmay be determined based on an actual situation. This is not limited inthis application. In an example, the preset time interval may be 1second, and the preset quantity may be 2. In this case, after obtainingthe 1st first image, the terminal obtains the 2nd first image when 1second elapses. In other words, a time interval between obtaining thetwo first images by the terminal is 1 second. If the terminal receivesthe photographing instruction after 5 seconds starting from obtainingthe 1st first image, the terminal obtains the two first images withinthe first 1 second, and no longer obtains a first image within theremaining 4 seconds.

In another example, the terminal obtains one first image each time asecond time interval elapses, and when a quantity of obtained firstimages exceeds the preset quantity, retains the preset quantity ofrecently obtained first images. For example, the second time interval is1 second, and the preset quantity is 2. If the terminal receives aphotographing instruction after 5 seconds starting from obtaining the1st first image, the terminal obtains a total of five first imageswithin the 5 seconds, and the terminal may retain the last obtained twofirst images. In an example, the terminal establishes a buffer in a mainmemory, and buffers one first image at an interval of a preset timeinterval. First images whose quantity does not exceed a preset quantityare maintained in the buffer based on a first in first out (First InputFirst Output, FIFO) mechanism. For example, a buffer is established in amain memory, and a first image in a preview phase of a camera isbuffered. For example, one first image is buffered at an interval of 1second, and three first images are always maintained in the buffer basedon the FIFO mechanism. After the terminal receives a photographinginstruction, the terminal may continuously photograph three secondimages. When detecting and removing a moving target, the terminal mayuse the three first images and the three second images as a plurality ofto-be-processed images. Obtaining a plurality of second images in aphotographing phase by a terminal is described in detail in thefollowing.

In another example, the terminal obtains two or more first images withina preset time interval (also referred to as a third time interval orthird duration). The preset time interval is a time interval betweenobtaining the 1st first image by the terminal and obtaining the lastfirst image by the terminal. The preset time interval may be determinedbased on an actual situation. This is not limited in this application.For example, if the preset time interval is 2 seconds, and one image isobtained at an interval of 0.5 second, five images need to be obtained.

Optionally, when the terminal obtains the first images, or when theterminal completes obtaining the first images, the terminal may sendprompt information to the user. The prompt information may include avoice prompt, a visual prompt, a vibration prompt, or the like. In anexample, as shown in FIG. 5, the terminal may send forth, by using aspeaker, voice prompt information “An image is being obtained. Do notshake.” In another example, as shown in FIG. 6, the terminal may sendvisual prompt information. For example, a dynamic icon used to indicatethat an image is being obtained may be displayed on a display screen ofthe terminal, and a shape of the icon may be, but is not limited to, adownward arrow or a vortex shape; or the screen flickers, prompting theuser that the terminal is obtaining an image. In another example, asshown in FIG. 7, when obtaining the first images, the terminal maydisplay, on the display screen, a quantity of obtained first images or aquantity of first images that still need to be obtained. Alternatively,when obtaining the first images, the terminal may display, on thedisplay screen, a size of a used cache capacity or a size of a remainingcache capacity.

Step 303: The terminal receives a photographing instruction.

In an example, the terminal receives a photographing instruction sent bythe user, to enter the photographing phase and obtain the second images.The user may send the photographing instruction to the terminal in aplurality of manners. For example, when the user taps a photographingfunction icon displayed on the screen of the terminal, or when the userpresses a function key of the terminal, or when the user sends a“photographing” voice, or when the user makes a preset gesture (forexample, “O”), it may be considered as sending a photographinginstruction to the terminal.

Optionally, before receiving the photographing instruction sent by theuser, the terminal may prompt the user to send the photographinginstruction, to inform the user that the obtaining of the first imagesis completed, and the terminal may receive the photographinginstruction. The terminal may prompt the user when a condition is met.The condition includes: The terminal has obtained the preset quantity offirst images; a cache of the terminal is already full; or duration ofthe preview phase of the terminal exceeds a preset duration threshold.The preset duration threshold may be determined based on an actualsituation. This is not limited in this application.

Optionally, when the terminal receives the photographing instruction, inother words, when the terminal starts to obtain the second images, theterminal may record a second moment t2 at which the terminal starts toobtain the second images.

Step 304: The terminal obtains at least one second image.

The terminal starts to obtain the at least one second image whenreceiving the photographing instruction. In other words, the terminalenters a photographing phase, and photographs a photographed person.

in an example, the terminal may obtain one second image in thephotographing phase. Optionally, after the terminal obtains one secondimage, the terminal may prompt the user that the obtaining of the secondimage is completed. A prompt manner is not limited in this embodiment ofthe present invention.

In another example, the terminal may obtain a plurality of second imagesin the photographing phase, for example, continuously obtain two orthree second images. Optionally, after the terminal obtains a pluralityof second images, the terminal may prompt the user that the obtaining ofthe second images is completed. A prompt manner is not limited in thisembodiment of the present invention.

Optionally, because the terminal may shake in the photographing phase,the terminal may determine, in the photographing phase, whether theterminal is in the stable state. When the terminal is in the stablestate, the terminal obtains at least one second image. When the terminalis in the unstable state, the terminal may stop obtaining the secondimage; and when determining that the terminal is in the stable stateagain, the terminal starts to obtain the second image again. Fordetermining of stability of the terminal, refer to the description inthe foregoing step 302. Details are not described herein again.

The following further describes a case in which the terminal obtains theplurality of second images in the photographing phase.

In an example, the terminal may first obtain one second image, and thenobtain one second image each time a preset time interval (also referredto as a second time interval or second duration) elapses, until a secondquantity of second images are obtained. The preset time interval is atime interval between obtaining one second image by the terminal andobtaining another second image by the terminal. The preset time intervalmay be determined based on an actual situation. This is not limited inthis application. In an example, the preset time interval may be 1second, and the second quantity may be 2. In this case, after obtainingthe 1st second image, and the terminal obtains the 2nd second image when1 second elapses. In other words, a time interval for obtaining all thetwo second images by the terminal is 1 second.

In another example, the terminal obtains the plurality of second imageswithin a preset time interval (also referred to as a fourth timeinterval or fourth duration). The preset time interval is a timeinterval between obtaining the 1st second image by the terminal andobtaining the last second image by the terminal. The preset timeinterval may be determined based on an actual situation. This is notlimited in this application. For example, if the preset time interval is2 seconds, and one image is obtained at an interval of 0.5 second, fiveimages need to be obtained.

Optionally, when the terminal obtains the second images, or when theterminal completes obtaining the second images, the terminal may sendprompt information to the user. The prompt information may include avoice prompt, a visual prompt, a vibration prompt, or the like, in anexample, as shown in FIG. 5, the terminal may send forth, by using aspeaker, voice prompt information “An image is being obtained. Do notshake.” In another example, as shown in FIG. 6, the terminal may sendvisual prompt information. For example, a dynamic icon used to indicatethat an image is being obtained may be displayed on a display screen ofthe terminal, and a shape of the icon may be, but is not limited to, adownward arrow or a vortex shape; or the screen flickers, prompting theuser that the terminal is obtaining an image. In another example, asshown in FIG. 7, When obtaining the second images, the terminal maydisplay, on the display screen, a quantity of obtained second images ora quantity of second images that still need to be obtained.Alternatively, when obtaining the second images, the terminal maydisplay, on the display screen, a size of a used cache capacity or asize of a remaining cache capacity.

Step 305: The terminal detects a moving target based on the first imageand the second image.

In an example, when the terminal obtains one first image in the previewphase, and obtains one second image in the photographing phase, theterminal inputs the first image and the second image into a movingtarget detection algorithm, to detect the moving target.

In another example, when the terminal obtains a plurality of firstimages in the preview phase, and obtains one second image in thephotographing phase, because usually a longer time interval between thefirst images and the second image indicates a larger moving distance ofthe moving target, the terminal inputs the 1st first image in theplurality of first images and the second image into the moving targetdetection algorithm, to detect the moving target. In this way, theterminal can more accurately detect the moving target.

Optionally, the terminal inputs clearest first images in the pluralityof first images and the second image into the moving target detectionalgorithm, to detect the moving target. In this way, the terminal canmore accurately detect the moving target. An existing method may be usedto determine a clearness status of the preview image. Details are notdescribed in this application.

Optionally, the terminal may separately input each of the plurality offirst images and the second image into the moving target detectionalgorithm, to detect the moving target. In this way, when there are aplurality of moving targets, the terminal can more accurately determinethe moving targets.

In another example, when the terminal obtains one first image in thepreview phase, and obtains a plurality of second images in thephotographing phase, based on a same reason in the foregoing example,the terminal inputs the first image and the last second image in theplurality of second images into the moving target detection algorithm,to detect the moving target.

Optionally, the terminal inputs the first image and clearest secondimages in the plurality of second images into the moving targetdetection algorithm, to detect the moving target. In this way, theterminal can more accurately detect the moving target.

Optionally, when there are a plurality of moving targets, the terminalmay separately input the first image and each of the plurality of secondimages into the moving target detection algorithm, to detect the movingtargets. In this way, when there are a plurality of moving targets, theterminal can more accurately determine the moving targets.

For a case in which the terminal obtains a plurality of first images inthe preview phase and obtains a plurality of second images in thephotographing phase, refer to the foregoing examples. Details are notdescribed in this application.

In the foregoing examples, the terminal may detect the moving target inthe first image and the second image by using an image differentiationmethod. Specifically, the terminal aligns the first image with thesecond image, and then performs image differentiation on the first imageand the second image that have been aligned, thereby implementing themoving target detection.

It should be noted that the terminal may alternatively detect the movingtarget in the first image and the second image by using another existingmoving target detection method. Details are not described in thisapplication.

Step 306: The terminal splits the moving target from the first image andthe second image, and performs fusion processing on the first image andthe second image after the splitting.

In an example, after the moving target is detected by performing step305, the moving target may be split from each first image and eachsecond image. Because deformation occurs in an image obtained after themoving target is split, the image is complemented by using a backgroundimage, in another image, at a location of the removed moving target. Aprocess of complementing an image based on another image is referred toas the fusion processing.

In another example, the moving target may not need to be split from eachfirst image and each second image, but clearest images may be firstsifted out from the at least one first image and the at least one secondimage. The moving target is split only from the clearest images, andthen the clearest images are complemented by using a background image,in another image, at a location of the removed moving target.

It should be noted that the terminal may alternatively use anotherexisting fusion processing method to perform fusion processing on thefirst image and the second image after the splitting. Details are notdescribed in this application.

As shown in FIG. 3, in both step 302 and step 304, the terminal obtainsthe image. To better understand an occasion at which the terminalobtains the image, the following further describes, with reference toFIG. 8 or FIG. 9, the occasion at which the terminal obtains the image.

FIG. 8 is a schematic diagram of obtaining an image by a terminalaccording to an embodiment of the present invention. As shown in FIG. 8,the terminal obtains the image in two phases, namely, a preview phaseand a photographing phase. The preview phase starts from obtaining the1st first image by the terminal, and ends with receiving a photographinginstruction by the terminal. The photographing phase starts fromreceiving the photographing instruction by the terminal, and ends withobtaining the last second image by the terminal. In other words, acritical point between the preview phase and the photographing phase isreceiving the photographing instruction by the terminal. It may beunderstood that, when a transmission time of the photographinginstruction may be ignored, a time at which the terminal receives thephotographing instruction and a time at which a user presses aphotographing key may be considered to be the same. As shown in FIG. 8,the terminal records a first moment t1 at which the terminal obtains the1st first image, and records a second moment t2 at which the terminalreceives the photographing instruction, thereby determining previewduration T1=t2−t1. When the preview duration T1 is less than a presettotal image obtaining duration threshold T, the terminal determines thatphotographing duration T2=T−T1. T2=t3−t2, and t3 is a third moment atwhich the terminal obtains the last second image. For example, if thepreview duration T1 is 2 seconds, and the total image obtaining durationthreshold T is 4 seconds, the photographing duration T2 is 2 seconds.For another example, if the preview duration T1 is 3 seconds, and thetotal image obtaining duration threshold T is 6 seconds, thephotographing duration T2 is 3 seconds. It can be learned from theforegoing that, a time sensed by the user is usually the photographingduration T2. Because T2 is less than the total image obtaining durationthreshold T, user experience is good. It may be understood that thetotal image obtaining duration threshold T may be determined based on anactual situation. For example, to meet a requirement of removing amoving target, the total image obtaining duration threshold T may besmallest duration that elapses between obtaining first images andobtaining second images.

FIG. 9 is another schematic diagram of obtaining an image by a terminalaccording to an embodiment of the present invention. As shown in FIG. 9,the terminal obtains the image in two phases, namely, a preview phaseand a photographing phase. The preview phase starts from obtaining the1st first image by the terminal, and ends with receiving a photographinginstruction by the terminal. The photographing phase starts fromreceiving the photographing instruction by the terminal, and ends withobtaining the last second image by the terminal. In other words, acritical point between the preview phase and the photographing phase isreceiving the photographing instruction by the terminal. It may beunderstood that, when a transmission time of the photographinginstruction may be ignored, a time at which the terminal receives thephotographing instruction and a time at which a user presses aphotographing key may be considered to be the same. As shown in FIG. 9,the terminal records a first moment t1 at which the terminal obtains the1st first image, and records a second moment t2 at which the terminalreceives the photographing instruction, thereby determining previewduration T1=t2−t1. When the preview duration T is greater than or equalto a preset total image obtaining duration threshold T, the terminaldoes not need to determine photographing duration, and directly obtainsa preset quantity of photographed images. T2=t3−t2, and t3 is a thirdmoment at which the terminal obtains the last second image. For example,the preview duration T1 is 5 seconds, and the total image obtainingduration threshold T is 4 seconds. In this case, a second image isdirectly obtained (for example, duration T2 is 1 second). It can belearned from the foregoing that, a time sensed by the user is usuallythe photographing duration T2. Because T2 is inevitably less than thetotal image obtaining duration threshold T, user experience is good. Thetotal image obtaining duration threshold T may be determined based on anactual situation. For example, to meet a requirement of removing amoving target, the total image obtaining duration threshold T may besmallest duration that elapses between obtaining first images andobtaining second images.

It should be noted that, if the terminal obtains a first image whenenabling a camera function, the terminal records that the first momentt1 at which the terminal obtains the 1st first image is a moment atwhich the terminal enables the camera function. If the terminal firstdetermines whether the terminal is in a stable state after enabling thecamera function, and obtains a first image only when the terminal is inthe stable state, the terminal records that the first moment t1 at whichthe terminal obtains the 1st first image is a moment at which theterminal determines that the terminal is in the stable state. If theterminal shakes after determining that the terminal is in the stablestate, the terminal records that the first moment t1 at which theterminal obtains the 1st first image is a moment at which the terminaldetermines, for the last time, that the terminal is in the stable state.If the terminal obtains a plurality of first images, and stores only apreset quantity of recently obtained first images in a cache, theterminal records that the first moment t1 at which the terminal obtainsthe 1st first image is an obtaining time of one first image that isearliest obtained and that is stored in the cache.

In this embodiment of the present invention, it is not that the terminalobtains the plurality of images only after receiving the photographinginstruction, but the terminal starts to obtain the images in the previewphase before receiving the photographing instruction. Therefore, aquantity of images that need to be obtained after the photographinginstruction is received is reduced, so that a required photographingtime is apparently shortened, photographing efficiency is high, userexperience is good.

FIG. 10 is a schematic flowchart of a moving target detection methodaccording to an embodiment of the present invention. The method may beused as an independent processing procedure used for moving targetdetection, or may be used as an example for implementing step 305, to becombined with the other steps in FIG. 3. The method includes thefollowing steps.

Step 1001: The terminal determines a depth of field map of the firstimage based on the first image.

Step 1002: The terminal determines a depth of field map of the secondimage based on the second image.

Because a same method may be used to determine the depth of field map ofthe first image and determine the depth of field map of the secondimage, the method for determining the depth of field maps is describedbelow in a unified manner.

Step 1003: The terminal detects the moving target based on the depth offield map of the first image and the depth of field map of the firstimage.

Because a boundary of the moving target can be apparently reflected inthe depth of field maps, the moving target can be accurately detected.

In an example, the terminal has dual camera lenses. The terminal canaccurately determine depth of field information by using the dual cameralenses.

A common detection method is based on a moving target detectionalgorithm for a two-dimensional image, and has a capability boundary,and cannot provide good coverage for all scenes. However, in thisembodiment of the present invention, the dual camera lenses obtain thedepth of field information, and a foreground image is separated from abackground image with reference to the depth of field information, sothat the moving target is accurately tracked and split. Foreground andbackground can be distinguished by using the obtained depth of fieldinformation, and a moving track of the moving target in the foregroundor the background can be accurately obtained, thereby perform imagesplitting on the corresponding foreground or background. The depth offield information may be used to determine a depth of field. Forexample, the depth of field information may be a value of the depth offield.

The following describes, with reference to FIG. 11, a depth of fielddetermining method provided in this embodiment of the present invention.FIG. 11 is a schematic diagram of a depth of field determining methodaccording to an embodiment of the present invention. A case in which twocamera lenses are the same and corresponding axes of their coordinatesystems are parallel to each other, but origin locations of the twocamera lenses are different is considered. It is assumed that C1 and C2are respectively optical center positions (namely, lens centers) of aleft camera lens and a right camera lens, a polar line distance betweenC1 and C2 is b, and focal lengths of the camera lenses are f. A point Pis a point in space, projection points of the point P on a left cameralens image and a right camera lens image are respectively P1 and P2, anda perpendicular distance between P and a connection line from C1 to C2is d. Lines perpendicular to imaging planes are respectively drawnthrough C1 and C2, and feet of perpendiculars are respectively A1 andA2. A line perpendicular to a baseline is drawn through P, and this lineand the baseline intersect at B.

Assuming that |A1P1|=1a, |A2P2|=1b, and |P2B|=a.

$\begin{matrix}{d = {{f\frac{a + {lb}}{lb}} = \frac{b\; f}{{l\; a} - {l\; b}}}} & (1)\end{matrix}$

It can be learned from the formula (1) that the distance d is depth offield information. The distance d is related to the baseline b, thefocal length f, and 1a-1b. 1a-1b is referred to as a parallax of thepoint P on two imaging planes, and reflects a location differencebetween image points of the point P on the two imaging planes. Because band f are known, to implement ranging of binocular stereoscopicparallax, the most crucial is to obtain the parallax 1a-1b, in otherwords, to implement correspondence between projection points of the samepoint P in space on the two images, namely, the left and right images.In addition, reducing the distance of the baseline b not only reduces alargest distance that can be measured, but also reduces precisionbetween relative depths of field. However, precision of the 1a-1b ismore dependent on a size of a pixel. During actual calculation, thisprecision is not less than one pixel.

During actual calculation of a depth of field, a plurality of differentplanes may be obtained through division between a largest distance and asmallest distance. Precision between each plane is determined by actualprecision of an algorithm, and in this way, impact of an error can bereduced, and precision of the depth of field calculation can beimproved.

FIG. 12 is another schematic diagram of a depth of field determiningmethod according to an embodiment of the present invention. Theforegoing depth of field calculation formula is based on two parallelsame camera lenses. However, during actual use, there are actually manyproblems. For example, in FIG. 12, the two camera lenses always havesome scenes that cannot cross a scene of each other. Therefore, actualfield of view (field angle, FOV) designs of the two camera lenses aredifferent. A primary camera lens is used to obtain an actual image, andan image of a secondary camera lens is mainly used as reference forcalculating a depth of field. An FOV of the secondary camera lens isusually greater than that of the primary camera lens, but even so, arelatively close object may still not be in images of the two cameralenses at the same time. As shown in FIG. 12, θ is the FOV of theprimary camera lens, φ is the FOV of the secondary camera lens, Z is adepth of field, and b is a baseline. A formula (2) for calculating thedepth of field Z is as follows:

$\begin{matrix}{\phi = {2\;{\tan^{- 1}\left( \frac{Z{{an}\left( {{\theta\text{/}2} + b} \right)}}{Z} \right)}}} & (2)\end{matrix}$

For the case in FIG. 12, the formula for calculating the depth of fieldneeds to be adjusted. For example, because the two camera lenses havedifferent imaging, and object zoom ratios, changing image zoom ratios tothe same needs to be considered during distance calculation. Actually,not only the zoom ratios, but also distortion, a posture difference, andthe like all need to be adjusted. This is very important correctionduring the depth of field calculation.

FIG. 13 is a schematic diagram of obtaining a depth of field map by aterminal according to an embodiment of the present invention. 1301 inFIG. 13 is a reference image, 1302 in FIG. 13 is a target image, and adifference image, namely, 1303 in FIG. 13, between 1301 in FIGS. 13 and1302 in FIG. 13 is determined based on 1301 in FIGS. 13 and 1303 in FIG.13. The difference image represents a displacement difference, of a samepoint, between 1301 in FIGS. 13 and 1302 in FIG. 13. Because adisplacement difference in triangulation location is proportional to adepth of field, the difference image is directly used as the depth offield map in many cases. In most cases, this image is stored in a formof a grayscale image. Through comparison between 1301 in FIG. 13, 1302in FIG. 13, and 1303 in FIG. 13, it can be found that boundaries ofadjacent objects are not clear in 1301 in FIG. 13 and 1302 in FIG. 13,but the boundaries of the adjacent objects in 1303 in FIG. 13 becomeclear, thereby facilitating splitting of a target object from the image.

In this embodiment of the present invention, a three-dimensional (3D)scene may be further reconstructed by using the depth of field map.Calibration, correction, stereoscopic correspondence, and triangulationsurvey may be used. After the 3D scene is reconstructed, each object inthe image can be more easily identified, and the target object can beaccurately split.

It should be noted that the method in FIG. 13 may be used to determinean image boundary of a first image, or may be used to determine an imageboundary of a second image. Images obtained by using a terminal havingdual camera lenses each have a reference image and a target image.

In addition, a process of the splitting and the fusion processing instep 306 in FIG. 3 is further described.

FIG. 14 is a schematic diagram of a method for performing fusionprocessing on a plurality of images according to an embodiment of thepresent invention. As shown in FIG. 14, an image 1401 and an image 1402in FIG. 14 may be used as images for the fusion processing. A movingtarget 1411 may be first split from the image 1401, and then the image1401 is complemented by using a background image 1412, in the image1402, at a location of the removed moving target.

It may be understood that, when the clearest image is complemented byusing a background image, in another image, at a location of a removedmoving target, the background picture, in the another picture, at thelocation of the removed moving target is required not to include themoving target. For example, the background picture 1412, in the image1402 in FIG. 14, at the location of the removed moving target does notinclude the moving target.

It may be understood that there may be two or more images for performingfusion processing. When relatively many moving targets need to beremoved from an image, and two images are insufficient to be fused toobtain a complete image that has no moving target, fusion processing maybe performed by using more images, to obtain a complete image that hasno moving target.

In this embodiment of the present invention, an improved detectionmethod is provided. Compared with moving target detection and removalaccording to a common detection method, detection accuracy is high, noproblem of image deformation occurs after the moving target removal, andan effect is ideal.

FIG. 15 is a schematic structural diagram of a terminal according to anembodiment of the present invention. The terminal is configured toperform the image processing method provided in the embodiments of thepresent invention. The terminal includes:

-   -   a display unit 1501, configured to display a preview image;    -   a processing unit 1502, configured to obtain at least one first        image in the preview image displayed by the display unit 1501        and    -   a receiving unit 1503, configured to receive a photographing        instruction.

The processing unit 1502 is further configured to: obtain at least onesecond image; detect a moving target based on the first image and thesecond image; and split the moving target from the first image and thesecond image, and perform fusion processing on the first image and thesecond image after the splitting.

In an example, that the display unit 1501 displays the preview imageincludes: displaying, by the display unit 1501, the preview image when acamera function of the terminal is enabled; or displaying, by thedisplay unit 1501, the preview image when a camera function of theterminal enters a first photo mode; or displaying, by the display unit1501, the preview image when the receiving unit 1503 receives thephotographing instruction and a first time interval elapses.

In an example, that the processing unit 1502 obtains the at least onefirst image in the preview image displayed by the display unit 1501includes: obtaining, by the processing unit 1502, a preset quantity offirst images in the preview image displayed by the display unit 1501.

In an example, the obtaining, by the processing unit 1502, a presetquantity of first images in the preview image displayed by the displayunit 1501 includes: obtaining, by the processing unit 1502 each time asecond time interval elapses, one of the first images in the previewimage displayed by the display unit 1501, until the preset quantity ofthe first images in the preview image are obtained.

In an example, the obtaining, by the processing unit 1502, a presetquantity of first images in the preview image displayed by the displayunit 1501 includes: obtaining, by the processing unit 1502 each time asecond time interval elapses, one of the first images in the previewimage displayed by the display unit 1501, and when a quantity ofobtained first images in the preview image exceeds the preset quantity,retaining the preset quantity of recently obtained first images in thepreview image.

In an example, that the processing unit 1502 obtains the at least onefirst image in the preview image displayed by the display unit 1501includes: obtaining, by the processing unit 1502 within a third timeinterval, at least two first images in the preview image displayed bythe display unit 1501.

In an example, before the processing unit 1502 obtains the at least onefirst image in the preview image displayed by the display unit 1501, theprocessing unit 1502 is further configured to: obtain motion data of theterminal; and determine, based on the motion data, that the terminal isin a stable stale.

In an example, that the processing unit 1502 detects the moving targetbased on the first image and the second image includes: determining, bythe processing unit 1502, depth of field information of the first imageand depth of field information of the second image based on the firstimage and the second image; and detecting, by the processing unit 1502,the moving target based on the depth of field information.

In an example, the terminal has dual camera lenses.

In this embodiment of the present invention, it is not that theprocessing unit 1502 obtains the plurality of images only after thereceiving unit 1503 receives the photographing instruction, but theprocessing unit 1502 starts to obtain the images in the preview phasebefore the receiving unit 1503 receives the photographing instruction.Therefore, a quantity of images that need to be obtained by thereceiving unit 1503 after the photographing instruction is received isreduced, so that a required photographing time is apparently shortened,photographing efficiency is high, and user experience is good.

The terminal provided in this embodiment of the present invention may beconfigured to perform the image processing method provided in theforegoing embodiments of the present invention. For correspondingfeatures and descriptions, refer to related content of the foregoingmethod. Details are not described in this embodiment again.

In addition, the RF circuit 110 and the input unit 130 in the terminalshown in FIG. 2 may correspond to the receiving unit 1503 of theterminal in FIG. 15. The display unit 140 may correspond to the displayunit 1501 in FIG. 15. The processor 150 and the sensor 170 maycorrespond to the processing unit 1502 in FIG. 15. Details are notdescribed herein again.

FIG. 16 is a schematic structural diagram of a terminal according to anembodiment of the present invention. The terminal provided in thisembodiment of the present invention may be configured to implement themethod implemented in the foregoing embodiment of the present inventionshown in FIG. 3 or FIG. 10. For ease of description, only parts relatedto this embodiment of the present invention are illustrated. Forspecific technical details that are not disclosed, refer to theforegoing method embodiments of the present invention, and another partof this application, such as the terminal shown in FIG. 2. As shown inFIG. 16, the terminal 1600 includes a processor 1601, a camera lens1602, a memory 1603, a display screen 1604, and a sensor 1605.

The memory 1603 is configured to store a program instruction.

The processor 1601 is configured to perform the following operationsaccording to the program instruction stored in the memory 1603:

-   -   displaying a preview image by using the display screen 1604;    -   obtaining at least one first image in the preview image;    -   receiving a photographing instruction;    -   obtaining at least one second image by using the camera lens        1602;    -   detecting a moving target based on the first image and the        second image; and    -   splitting the moving target from the first image and the second        image, and performing fusion processing on the first image and        the second image after the splitting.

In an example, that the processor 1601 performs the operation ofdisplaying a preview image by using the display screen 1604 includes:displaying the preview image by using the display screen 1604 when acamera function of the terminal is enabled; or displaying the previewimage by using the display screen 1604 when a camera function of theterminal enters a first photo mode; or displaying the preview image byusing the display screen 1604 when receiving the photographinginstruction and a first time interval elapses.

In an example, that the processor 1601 performs the operation ofobtaining at least one first image in the preview image includes:obtaining a preset quantity of first images in the preview image.

In an example, that the processor 1601 performs the operation ofobtaining a preset quantity of first images in the preview imageincludes: obtaining one of the first images in the preview image eachtime a second time interval elapses, until the preset quantity of firstimages in the preview image are obtained.

In an example, that the processor 1601 performs the operation ofobtaining a preset quantity of first images in the preview imageincludes: obtaining one of the first images in the preview image eachtime a second time interval elapses, and when a quantity of obtainedfirst images in the preview image exceeds the preset quantity, retainingthe preset quantity of recently obtained first images in the previewimage.

In an example, that the processor 1601 performs the operation ofobtaining at least one first image in the preview image includes:obtaining at least two first images in the preview image within a thirdtime interval.

In an example, before the processor 1601 performs the operation ofobtaining at least one first image in the preview image, the processor1601 is further configured to perform the following operations accordingto the program instruction stored in the memory 1603: obtaining motiondata of the terminal by using the sensor 1605; and determining, based onthe motion data, that the terminal is in a stable state.

In an example, that the processor 1601 performs the operation ofdetecting a moving target based on the first image and the second imageincludes: determining depth of field information of the first image anddepth of field information of the second image based on the first imageand the second image; and detecting the moving target based on the depthof field information.

In an example, the cameras lens 1602 is dual camera lenses.

In this embodiment of the present invention, it is not that theprocessor 1601 obtains the plurality of images only after receiving thephotographing instruction, but the processor 1601 starts to obtain theimages in the preview phase before receiving the photographinginstruction, Therefore, a quantity of images that need to be obtainedafter the photographing instruction is received is reduced, so that arequired photographing time is apparently shortened, photographingefficiency is high, and user experience is good.

An embodiment of the present invention further provides a chipapparatus. The chip includes a processing unit, configured to performthe methods shown in FIG. 3 to FIG. 14.

An embodiment of the present invention further provides a chipapparatus, and the chip apparatus includes a processor and a memory. Thememory includes an instruction, and the processor runs the instructionto perform the methods shown in FIG. 3 to FIG. 14.

In this embodiment of the present invention, the chip apparatus may be achip in a terminal, and the chip includes: a processing unit and acommunications unit. The processing unit may be, for example, aprocessor, and the processor may be a processor in various types ofprocessors 150 described above. The communications unit may be, forexample, an input/output interface, a pin, or a circuit. Thecommunications unit includes a system bus. Optionally, the chip furtherincludes a storage unit. The storage unit may be a memory inside thechip, for example, a register, a cache, a random access memory (randomaccess memory, RAM), an EEPROM, or a FLASH. Alternatively, the storageunit may be a memory located outside the chip, and the memory may be amemory in various types of memories 120 described above. The processoris connected to the memory, and the processor may run the instructionstored in the memory, to enable the chip apparatus to perform themethods shown in FIG. 3 to FIG. 14.

All or some of the foregoing embodiments of the present invention may beimplemented by using software, hardware, firmware, or any combinationthereof. When software is used to implement the embodiments, all or someof the embodiments may be implemented in a form of a computer programproduct. The computer program product includes one or more computerinstructions. When the computer program instructions are loaded andexecuted on a computer, all or some of procedures or functions accordingto the embodiments of the present invention are generated. The computermay be a general-purpose computer, a dedicated computer, a computernetwork, or another programmable apparatus. The computer instructionsmay be stored in a computer-readable storage medium, or may betransmitted from a computer-readable medium to another computer-readablemedium. For example, the computer instructions may be transmitted from awebsite, a computer, a server, or a data center in a wired (for example,coaxial cable, optical fiber, digital subscriber line (DigitalSubscriber Line, DSL)) manner or a wireless (for example, infrared,radio, or microwave) manner to another website, computer, server, ordata center. The computer-readable storage medium may be any usablemedium accessible by a computer, or a data storage device, such as aserver or a data center, including one or more usable mediums that areintegrated. The usable medium may be a magnetic medium (for example, afloppy disk, a hard disk, or a magnetic tape), an optical medium (forexample, a DVD), a semiconducting medium (for example, a solid-statedrive (Solid State Disk, SSD)), or the like.

The objectives, technical solutions, and beneficial effects of thepresent invention are further described in detail in the foregoingspecific implementations. It should be understood that the foregoingdescriptions are merely specific implementations of the presentinvention, but are not intended to limit the protection scope of thepresent invention. Any modification, equivalent replacement,improvement, or the like made based on the technical solutions of thepresent invention shall fall within the protection scope of the presentinvention.

What is claimed is:
 1. An image processing method implemented by aterminal, wherein the image processing method comprises: displaying apreview image; obtaining a photographing instruction when displaying thepreview image; generating a target image in response to thephotographing instruction by: obtaining a first image in the previewimage, wherein obtaining the first image comprises obtaining a presetquantity of first images in the preview image by: obtaining one of thefirst images in the preview image each time a second time intervalelapses; and retaining the preset quantity of the first images that wasobtained last in the preview image when a quantity of obtained firstimages in the preview image exceeds the preset quantity; obtaining asecond image; determining a moving object based on the first image andthe second image; and fusing the first image and the second image toobtain the target image, wherein the target image does not include themoving object, and wherein displaying the preview image comprises:displaying the preview image when a camera function of the terminal isenabled; displaying the preview image when the camera function of theterminal enters a first photo mode; or displaying the preview image whenthe terminal receives the photographing instruction and a first timeinterval elapses.
 2. The image processing method of claim 1, whereinobtaining the preset quantity of the first images in the preview imagecomprises obtaining the one of the first images in the preview imageeach time the second time interval elapses until the preset quantity ofthe first images in the preview image is obtained.
 3. The imageprocessing method of claim 1, wherein before obtaining the first imagein the preview image, the image processing method further comprises:obtaining motion data of the terminal; and determining, based on themotion data, that the terminal is in a stable state.
 4. The imageprocessing method of claim 3, wherein determining the moving objectbased on the first image and the second image comprises: determiningdepth of field information of the first image and depth of fieldinformation of the second image based on the first image and the secondimage; and detecting the moving object based on the depth of fieldinformation of the first image and the depth of field information of thesecond image.
 5. The image processing method of claim 4, wherein theterminal comprises dual camera lenses.
 6. The image processing method ofclaim 1, wherein obtaining the first image comprises obtaining at leasttwo first images in the preview image within a third time interval.
 7. Aterminal, comprising: a processor; and a memory coupled to the processorand storing instructions that, when executed by the processor, cause theterminal to be configured to: display a preview image, wherein todisplay the preview image the instructions cause the terminal to beconfigured to: display the preview image when a camera function of theterminal is enabled; display the preview image when the camera functionof the terminal enters a first photo mode; or display the preview imagewhen the terminal receives a photographing instruction and a first timeinterval elapses; obtain the photographing instruction when displayingthe preview image; and generate a target image in response to thephotographing instruction by: obtaining a first image in the previewimage, wherein obtaining the first image comprises obtaining a presetquantity of first images in the preview image by: obtaining one of thefirst images in the preview image each time a second time intervalelapses; and retaining the preset quantity of the first images that wasobtained last in the preview image when a quantity of obtained firstimages in the preview image exceeds the preset quantity; obtaining asecond image; determining a moving object based on the first image andthe second image; and fusing the first image and the second image toobtain the target image, wherein the target image does not include themoving object.
 8. The terminal of claim 7, wherein to obtain the presetquantity of the first images in the preview image, the instructionscause the terminal to be configured to obtain the one of the firstimages in the preview image each time the second time interval elapsesuntil the preset quantity of first images in the preview image isobtained.
 9. The terminal of claim 7, wherein before obtaining the firstimage in the preview image, the instructions further cause the terminalto be configured to: obtain motion data of the terminal; and determine,based on the motion data, that the terminal is in a stable state. 10.The terminal of claim 9, further comprising dual camera lenses.
 11. Theterminal of claim 7, wherein to obtain the first image in the previewimage, the instructions cause the terminal to be configured to obtain atleast two first images in the preview image within a third timeinterval.
 12. The terminal of claim 11, wherein to determine the movingobject based on the first image and the second image the instructionscause the terminal to be configured to: determine depth of fieldinformation of the first image and depth of field information of thesecond image based on the first image and the second image; and detectthe moving target based on the depth of field information of the firstimage and the depth of field information of the second image.
 13. Theterminal of claim 7, wherein to display the preview image, theinstructions cause the processor to be configured to display the previewimage when the camera function of the terminal enters the first photomode.
 14. The terminal of claim 7, wherein to display the preview image,the instructions cause the processor to be configured to display thepreview image when the terminal receives the photographing instructionand the first time interval elapses.
 15. An image processing methodimplemented by a terminal, wherein the image processing methodcomprises: displaying a preview image; obtaining a photographinginstruction when displaying the preview image; generating a target imagein response to the photographing instruction by: obtaining a first imagein the preview image, wherein obtaining the first image comprisesobtaining a preset quantity of first images in the preview image by:obtaining one of the first images in the preview image each time asecond time interval elapses; and retaining the preset quantity of thefirst images that was obtained last in the preview image when a quantityof obtained first images in the preview image exceeds the presetquantity; obtaining a second image; determining a moving object based onthe first image and the second image; and fusing the first image and thesecond image to obtain the target image, wherein the target image doesnot include the moving object.
 16. The image processing method of claim15, wherein displaying the preview image comprises displaying thepreview image when a camera function of the terminal is enabled.
 17. Theimage processing method of claim 15, wherein displaying the previewimage comprises displaying the preview image when a camera function ofthe terminal enters a first photo mode.
 18. The image processing methodof claim 15, wherein displaying the preview image comprises displayingthe preview image when the terminal receives the photographinginstruction and a first time interval elapses.